Page({
  data: {
    steps: []
  },

  onLoad(options) {
    // 获取传递过来的步骤数据
    const steps = JSON.parse(options.steps || '[]');
    this.setData({ steps });
  },

  // 删除步骤
  deleteStep(e) {
    const { index } = e.currentTarget.dataset;
    const steps = this.data.steps;
    steps.splice(index, 1);
    this.setData({ steps });
  },

  // 完成调整
  onFinish() {
    const pages = getCurrentPages();
    const prevPage = pages[pages.length - 2];
    prevPage.setData({
      steps: this.data.steps
    });
    wx.navigateBack();
  },

  // 拖拽排序相关方法
  onDragStart(e) {
    this.setData({
      dragIndex: e.currentTarget.dataset.index
    });
  },

  onDragMove(e) {
    const { dragIndex } = this.data;
    const targetIndex = e.currentTarget.dataset.index;
    
    if (dragIndex === targetIndex) return;
    
    const steps = this.data.steps;
    const temp = steps[dragIndex];
    steps[dragIndex] = steps[targetIndex];
    steps[targetIndex] = temp;
    
    this.setData({
      steps,
      dragIndex: targetIndex
    });
  },

  // 返回上一页
  navigateBack() {
    wx.navigateBack();
  }
}); 